window.onload = function(){
	//获取节点
	var txtEma = document.getElementById("txtEma");
	var txtName = document.getElementById("txtName");
	var txtPwd = document.getElementById("txtPwd");
	var txtPwd2 = document.getElementById("txtPwd2");
	var txt1 = document.getElementById("txt1");
	var txt2 = document.getElementById("txt2");
	var txt3 = document.getElementById("txt3");
	var txt4 = document.getElementById("txt4");
	var btnSub = document.getElementById("btnSub");
	var regForm = document.getElementById("regForm");
	var a=0,b=0,c=0,d=0,sum=0;
//	var btnSub = document.getElementById("btnSub");
	console.log(txt1);//检测节点是否被获取
	//+++++++++++++++++++++++++++++++封装一个获取焦点的函数
   function juJiao(ju,juEma){
   	    ju.style.fontSize = "13px";
		ju.style.color = "#989898";
		ju.style.marginLeft = "5px";
		juEma.style.backgroundColor = "#F0FCD8";
   }
   //++++++++++++++++++++++++++++封装一个失去焦点的函数
   function shiJiao(shi,shiEma){
	    shiEma.style.backgroundColor = "#F8F4D0";
	    shi.style.backgroundColor = "#F8F4D0";
	    shi.style.border = "1px solid #858484"
	    shi.style.color = "#BA0000";
	    shi.style.fontSize = "13px";
	    shi.style.padding ="2px";
	    shi.style.marginLeft = "5px";
   }
	//+++++++++++++++++++++++++++封装一个初始化的函数
//	function chuShihua(chu){
//		chu.style.border = "0";
//		chu.style.background = "#fff";
//	}
	//给文本框添加事件
	//当鼠标获取焦点的时候     ++++++++++++++++++++++++++++++++++++++++++++++++++邮箱
	txtEma.onfocus = function(){
		juJiao(txt1,txtEma);
		txt1.innerHTML = "此邮箱将是您登录当当网的账号，并将用来接收验证邮箱";
		txt1.style.border = "0";
		txt1.style.background = "#fff";
       
		
	}//鼠标获取焦点结束符
	//当鼠标失去焦点的时候
	txtEma.onblur = function(){
		shiJiao(txt1,txtEma);
		if(txtEma.value == ""){
		    txt1.innerHTML = "电子邮箱是必填项，请输入您的Email地址";
//		    shiEma.focus();
//		    shiEma.select();
           
		}else if(txtEma.value.indexOf("@") == -1 || txtEma.value.indexOf(".") == -1){
		    	txt1.innerHTML = "请输入正确电子邮箱Email地址";
		    	console.log(txt1.innerHTML);
		}else{
			txt1.innerHTML = "<img src='images/register_write_ok.gif'>";
			txt1.style.marginLeft = "20px";
			txt1.style.border = "0";
			txt1.style.background = "#fff";
//			txt1.style.cssText ="";
			a=1;
		}
		
	}//鼠标失去焦点结束符
	
	//当鼠标获取焦点的时候     +++++++++++++++++++++++++++++++++++++++++++++++++昵称
	txtName.onfocus = function(){
		juJiao(txt2,txtName);
		txt2.innerHTML = "昵称可由大小写英文字母、数字组成，长度为4-20个字符";
	    txt2.style.border = "0";
		txt2.style.background = "#fff";
		
	}//鼠标获取焦点结束符
	//当鼠标失去焦点的时候
	txtName.onblur = function(){
		shiJiao(txt2,txtName);
		if(txtName.value == ""){
			    txt2.innerHTML = "昵称为必填项，请输入您的昵称";
		}else{
		      for(var i=0; i<txtName.value.length;i++){
			
			  if(txtName.value.length < 4 || txtName.value.length >20){
			    	txt2.innerHTML = "请输入4-20个字符的昵称";
			  }else if(parseInt(txtName.value.charAt(i)) >=0){
			  	console.log(txtName.value.charAt(i));
				txt2.innerHTML = "昵称不能为数字";
				shiJiao(txt2,txtName);
				break;
			  }else{
				txt2.innerHTML = "<img src='images/register_write_ok.gif'>";
				txt2.style.marginLeft = "20px";
				txt2.style.border = "0";
			    txt2.style.background = "#fff";
			    b=1;
			}
		 }
		}
	}//鼠标失去焦点结束符


     //当鼠标获取焦点的时候    ++++++++++++++++++++++++++++++++++++++++++密码
	txtPwd.onfocus = function(){
	    juJiao(txt3,txtPwd);
		txt3.innerHTML = "密码可由大小英文字母、数字组成，长度为10位以上";
		txt3.style.border = "0";
		txt3.style.background = "#fff";
	}//鼠标获取焦点结束符
	//当鼠标失去焦点的时候
	txtPwd.onblur = function(){
		 shiJiao(txt3,txtPwd);
		if(txtPwd.value == ""){
		    txt3.innerHTML = "密码为必填项，请设置您的密码";
		}else if(txtPwd.value.length <= 10){
		    	txt3.innerHTML = "请输入正确的密码";
		}else{
			txt3.innerHTML = "<img src='images/register_write_ok.gif'>";
			txt3.style.marginLeft = "20px";
			txt3.style.border = "0";
			txt3.style.background = "#fff";
			c=1;
		}
		
	}//鼠标失去焦点结束符
   
   //当鼠标获取焦点的时候    ++++++++++++++++++++++++++++++++++++重复密码
	txtPwd2.onfocus = function(){
		juJiao(txt4,txtPwd2);
		txt4.innerHTML = "请再输入一次您的密码";
		txt4.style.border = "0";
		txt4.style.background = "#fff";

	}//鼠标获取焦点结束符
	//当鼠标失去焦点的时候
	txtPwd2.onblur = function(){
		shiJiao(txt4,txtPwd2); 
		if(txtPwd2.value == ""){
		    txt4.innerHTML= "请再次输入您的密码"; 
		}else if(txtPwd.value != txtPwd2.value){
		    	txt4.innerHTML = "两次密码不一致，请重新输入";
		}else{
			txt4.innerHTML = "<img src='images/register_write_ok.gif'>";
			txt4.style.marginLeft = "20px";
			txt4.style.border = "0";
			txt4.style.background = "#fff";
			d=1;
		}
		
	}//鼠标失去焦点结束符
	
	//地区二级联动
	var oSelect = document.getElementsByTagName("select");//获取节点
	console.log(oSelect);//检测是否被获取
	    //创建两个数组
	    var city = ["北京市","山东省","湖南省","湖北省","广东省"];
	    var shi = ["朝阳区","济南","长沙","武汉","广州"];
	    var ht1 = "<option>请选择省/城市</option>";
	    for(var i=0;i<city.length;i++){
	    	ht1 = ht1 +"<option>"+city[i]+"</option>";
	    }
	    oSelect[0].innerHTML = ht1;
	    oSelect[0].onchange = function(){
	    	var j = city.indexOf(this.value);
	    	var ht2 ="<option>"+shi[j]+"</option>";
	    	
	    	if(oSelect[0].value =="请选择省/城市"){
	    		oSelect[1].innerHTML = "<option>请选择城市/地区</option>";
	    	}else{
	    		oSelect[1].innerHTML = ht2;
	    	}
	    }
	    	
	btnSub.onclick = function(){
		sum = a + b + c + d;
	    if(sum == 4){
	    	window.location = "login.html";
	    }
	}
	    
}//加载函数
